#include<iostream>

using namespace std;

int n, m;
char maze[50][50];
bool vis[50][50];
int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

bool in(int x, int y){
	return x >= 0 && x < n && y >= 0 && y < m;
}

bool dfs(int x, int y) {
	if (maze[x][y] == 'T') {
		return true;
	}
	vis[x][y] = true;
	maze[x][y] = '#';
	for (int i = 0; i < 4; i++) {
		int dx = x + dir[i][0];
		int dy = y + dir[i][1];
		if (in(dx, dy) && maze[dx][dy] != '*' && !vis[dx][dy]) {
			if (dfs(dx, dy)) {
				return true;
			}
		}
	}
	vis[x][y] = false;
	maze[x][y] = '.';
	return false;
}

int main(void) {	
	cin >> n >> m;  
	
	for (int i = 0; i < n; i++) {
		cin >> maze[i];
	}
	int sx, sy; 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (maze[i][j] == 'S') {
				sx = i, sy = j;
				break;
			}
		}
	}
	dfs(sx, sy);
	for (int i = 0; i < n; i++) {
		cout << maze[i] << endl;
	}
	return 0;
}
